package org.leonos.core.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.log.Log;
import org.leonos.core.common.Const;

/**
 * 异常拦截器
 * @author LeonXiao
 */
public class ExceptionInterceptor implements Interceptor{

    private final static Log log = Log.getLog(ExceptionInterceptor.class);

    @Override
    public void intercept(Invocation invocation) {
        try {
            invocation.invoke();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("出现异常：", e);
            invocation.getController().setAttr("ex", e.toString());
            invocation.getController().render(Const.EXCEPTION_VIEW, 500);
        }
    }

}
